﻿namespace TfsReportRenderer.CommandLine
{
    using System;

    using global::CommandLine;
    using global::CommandLine.Text;

    /// <summary>
    /// The options for executing the export.
    /// </summary>
    public class Options
    {
        /// <summary>
        /// Gets or sets the URL to the Team Project Collection.
        /// </summary>
        [Option('u', "url", Required = true, HelpText = "The URL to the Team Project Collection.")]
        public string Url { get; set; }

        /// <summary>
        /// Gets or sets the Team Project to use.
        /// </summary>
        [Option('t', "teamproject", Required = false, HelpText = "The Team Project to use (default = first project).")]
        public string Project { get; set; }

        /// <summary>
        /// Gets or sets the Test Plan to query.
        /// </summary>
        [Option('p', "plan", Required = false, HelpText = "The Test Plan to query (default = first plan).")]
        public string Plan { get; set; }

        /// <summary>
        /// Gets or sets the path and file name for the target file (without extension).
        /// </summary>
        [Option('o', "output", Required = false, HelpText = "The path and file name for the target file (default = \"report\").")]
        public string OutputFile { get; set; }

        /// <summary>
        /// Gets or sets the RDL file to use with the RDL renderer.
        /// </summary>
        [Option("RdlFile", Required = false, HelpText = "The path and file name for the RDL template to be rendered - only relevant when using the \"--r Rdl\" switch to invoke the RDL renderer (default = built in report).")]
        public string RdlFile { get; set; }

        /// <summary>
        /// Gets or sets the render file format.
        /// </summary>
        [Option('f', "format", Required = false, DefaultValue = SheetFormat.Excel, HelpText = "The target file format to be used to generate the output file (use \"Excel\" or \"Pdf\" - default = \"Excel\") - only relevant when using the \"--r Rdl\" switch to invoke the RDL renderer.")]
        public SheetFormat FileFormat { get; set; }

        /// <summary>
        /// Gets or sets the renderer.
        /// </summary>
        [Option('r', "renderer", Required = false, DefaultValue = SheetRenderer.Excel, HelpText = "The renderer to be used to generate the output file (use \"Excel\" to use ClosedXML, or \"Rdl\" to render an RDL-Report as PDF) (default = \"Excel\").")]
        public SheetRenderer Renderer { get; set; }

        /// <summary>
        /// Gets or sets the renderer.
        /// </summary>
        [Option('d', "date", Required = false, HelpText = "The date and time to use as a filter - the last results until this date and time will be reported.")]
        public DateTime? Date { get; set; }

        /// <summary>
        /// The command line parser will use this method to build up a help screen.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        [HelpOption]
        public string GetUsage()
        {
            var help = new HelpText
            {
                Heading = new HeadingInfo("TFS Detailed test report", this.GetType().Assembly.GetName().Version.ToString(3)),
                Copyright = new CopyrightInfo("for license information see\nhttps://tfstestreport.codeplex.com/", 2015),
                AdditionalNewLineAfterOption = true,
                AddDashesToOption = true
            };
            help.AddPreOptionsLine("\n");
            help.AddPreOptionsLine("Usage: TfsReportRenderer.CommandLine -u [url to TFS]");
            help.AddOptions(this);

            return help;
        }
    }
}